package com.smzd.framework.security.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.core.dao.IDao;
import com.smzd.framework.core.business.AbstractFGService;
import com.smzd.framework.security.dao.AuthorityDao;
import com.smzd.framework.security.domain.Authority;
import com.smzd.framework.utils.db.FGRowConverter;

@Service
public class AuthorityService extends AbstractFGService<Authority> {
    @Autowired
    private AuthorityDao dao;

    @Override
    protected IDao<Authority> getDao() {
        return dao;
    }

    @Override
    public FGRowConverter<Authority> getConverter() {
        return AuthorityService.converter;
    }

    private static FGRowConverter<Authority> converter = new FGRowConverter<Authority>() {
        @Override
        public Object[] convert(Authority elem) {
            Object[] fields = new Object[] {
                    elem.getId(),
                    elem.getName(),
                    elem.getAuthority(),
                    elem.getDescription()
            };
            return fields;
        }
    };

    public List<Authority> getAuthoritiesByClientAppId(int clientAppId) {
        return dao.getAuthoritiesByClientAppId(clientAppId);
    }
}
